<template>
	<view>
		<!--小程序端的标题-->
		<view class="cu-bar">
			<view class="action" @tap="BackPage">
				<u-icon name="arrow-left" color="#555555" size="35"></u-icon>
			</view>
		</view>
		<view>
			<!-- 轮播图 -->
			<view class="u-demo-wrap">
				<view class="u-demo-area">
					<u-toast ref="uToast"></u-toast>
					<u-swiper :height="400" :list="carouselList" :interval="3000" @click="click"></u-swiper>
				</view>
			</view>	
			<!-- 中部文字描述 -->
			<view class="sp_detail">
				<text style="color: #f9621c ;font-size: 33upx;">{{goodsInfo.price}}</text>
				<text style="margin-left: 50rpx;" v-for="(item,index) in classificationList">
				{{item}}
				</text>
				<view class="titles">{{goodsInfo.denomination}}</view>
				<!-- 优惠券 -->
				<!-- <view class="ticketlist">
					<view style="display: flex;width: 550rpx; overflow-x: scroll; overflow: auto;">
						<view class="ticket">
							<view class="left">
								<view class="use">领</view>
							</view>
							<view class="right">
								<view class="introduce">
									<view class="top">
										￥
										<text class="big">3</text>
										满88减3
									</view>
									<view class="date u-line-1">2019.11.28-2020.1.24</view>
								</view>
							</view>
						</view>
						<view class="ticket">
							<view class="left">
								<view class="use">领</view>
							</view>
							<view class="right">
								<view class="introduce">
									<view class="top">
										￥
										<text class="big">3</text>
										满88减3
									</view>
									<view class="date u-line-1">2019.11.28-2020.1.24</view>
								</view>
							</view>
						</view>
					</view>
					<view style="display: flex;flex-wrap: nowrap; color: #f9621c;align-items: center;line-height: 124rpx;padding-left: 30rpx;">领券 <u-icon name="arrow-right" color="#f9621c" size="28"></u-icon></view>
				</view> -->
				
				<!-- 优惠券列表 -->
				<view class="ticketlist" v-if="couponsInfo.length>0">
					<view class="ticket" v-for="(item,index) in couponsInfo">
						<view class="left">
							<view class="use" @click="getCoupon(item.id)">领</view>
						</view>
						<view class="right">
							<view class="introduce">
								<view class="top">
									￥
									<text class="big">{{item.price || '暂未设置'}}</text>
									{{item.rulesUse || '暂未设置'}}
								</view>
								<view class="date u-line-1">{{item.usageTime || '暂未设置'}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 商品详情富文本 -->
			<view class="fuwenben">
				<view class="xiangqin">
					<view class="xiangqin">
						<text class="henxian"></text>
						<text>商品详情</text>
						<text class="henxian"></text>
					</view>
				</view>
				<!-- <view class="u-content">
					<u-parse :html="detail.content"></u-parse>
				</view> -->
				<view v-for="(item,index) in detailList">
					<image style="width: 750rpx;"  mode="widthFix" :src="item"></image>
				</view>
				
			</view>
			
		</view>
	</view>
</template>

<script>
	const app = getApp();
	import _tool from '@/utils/tools.js';	//工具函数
	export default {
		data() {
			return {
				goodsInfo:{},
				carouselList:[],
				classificationList:[],
				detailList:[],
				couponsInfo:[],
				imgList: [{
						image: 'https://cdn.uviewui.com/uview/swiper/1.jpg',
						title: '昨夜星辰昨夜风，画楼西畔桂堂东'
					},
					{
						image: 'https://cdn.uviewui.com/uview/swiper/2.jpg',
						title: '身无彩凤双飞翼，心有灵犀一点通'
					},
					{
						image: 'https://cdn.uviewui.com/uview/swiper/3.jpg',
						title: '谁念西风独自凉，萧萧黄叶闭疏窗，沉思往事立残阳'
					}
				],
				detail: {
				}
			};
		},
		onReady() {
			_tool.setBarColor(true);
		},
		onLoad(options) {
			var that = this
			app.globalData.api.getGoods(options.id).then(res=>{
				that.goodsInfo = res.resultObj;
				that.carouselList = res.resultObj.carousel.split(',');
				that.classificationList = res.resultObj.classification.replace(/"/g,'').replace('[','').replace(']','').split(',');
				that.detailList = res.resultObj.product_details.replace(/"/g,'').replace('[','').replace(']','').split(',');
				app.globalData.api.getCouponsByMerchantId({merchantId:res.resultObj.merchant_id}).then(res2=>{
					that.couponsInfo = res2.resultObj
				});
			})
		},
		methods:{
			BackPage() {
				uni.navigateBack();
			},
			getCoupon(couponId){
				var userId = app.globalData.smmUser.id;
				app.globalData.api.addUserCoupon({userId:userId,couponId:couponId}).then(res=>{
					if(res.message == '操作成功!'){
						uni.showModal({
							title:res.resultObj
						})
					}
				});
			},
			click(e){
				
				console.log('e :>> ', e);
				uni.previewImage({
					urls:[this.carouselList[e]],
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cu-bar {
		padding-top: 70rpx;
		justify-content: space-between;
		background-color:rgba(0, 0, 0, 0);
		z-index: 30;
	}
	.u-demo-wrap{
		margin-top: -120rpx;
	}
	.sp_detail{
		width: 705rpx;
		margin: 20rpx auto;
		padding: 20rpx;
		border-radius: 20rpx;
		line-height: 53rpx;
		background-color: #ffffff;
		
		.titles{
			font-weight: bold;
			font-size: 30upx;
			line-height: 40upx;
			overflow: hidden;
			text-overflow: ellipsis;
			display:-webkit-box;
			-webkit-line-clamp:2;
			-webkit-box-orient:vertical;
		}
	}
	.ticketlist{
		display: flex;
		margin:20rpx 0 5rpx;
		width: 100%;
		overflow: auto;
		overflow-x: scroll ;
		
		.ticket {
			display: flex;
			margin-right: 20rpx;
			.left {
				display: flex;
				width: 100rpx;
				height: 130rpx;
				border-left: 7px solid #935035 !important;
				padding: 10rpx 20rpx;
				background-color: #fce999;
				border-top-left-radius: 20rpx;
				border-bottom-left-radius: 20rpx;
				// border-top-right-radius: 50rpx;
				// border-bottom-right-radius: 50rpx;
				border-right: dashed 2rpx rgb(224, 215, 211);
				.use{
					height: auto;
					font-size: 34rpx;
					border-radius: 40rpx;
					color: #7a7a7a!important;
					line-height: 100rpx;
					margin: 0 auto;
				}
			}
			.right {
				width: 250rpx;
				height: 130rpx;
				padding: 10rpx 20rpx;
				background-color: #fce999;
				border-top-right-radius: 20rpx;
				border-bottom-right-radius: 20rpx;
				// border-top-left-radius: 50rpx;
				// border-bottom-left-radius: 50rpx;
				display: flex;
				align-items: center;
				// border-left: dashed 2rpx rgb(224, 215, 211);
				.introduce {
					margin-left: 10rpx;
					.top{
						color:#935035;
						font-size: 28rpx;
						.big{
							font-size: 60rpx;
							font-weight: bold;
							margin-right: 10rpx;
						}
					}
					.date{
						margin-top: 10rpx;
						font-size: 20rpx;
						color: $u-type-info-dark;
					}
				}
			}
		}
	}
	.fuwenben{
		text-align: center;
		
		.xiangqin{
			display: flex;
			white-space: nowrap;
			color: #939393;
			align-items: center;
			margin: 20rpx auto;
			
			.henxian{
				width: 60rpx;
				height: 5rpx;
				margin: 0 10rpx;
				background-color: #d3d3d3;
			}
		}
	}
	

</style>
